package com.haoan.index.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.haoan.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.haoan.common.annotation.Log;
import com.haoan.common.core.controller.BaseController;
import com.haoan.common.core.domain.AjaxResult;
import com.haoan.common.enums.BusinessType;
import com.haoan.index.domain.Activity;
import com.haoan.index.service.ActivityService;
import com.haoan.common.utils.poi.ExcelUtil;
import com.haoan.common.core.page.TableDataInfo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 活动Controller
 *
 * @author autoGen
 * @date 2025-01-03
 */
@Api(value="活动",tags = "活动")
@RestController
@RequestMapping("/index/activity")
public class ActivityController extends BaseController
{
    @Resource
    private ActivityService activityService;

    /**
     * 查询活动列表
     */
    @Anonymous
    @ApiOperation("查询活动列表")
    @GetMapping("/list")
    public TableDataInfo list(Activity activity)
    {
        startPage();
        List<Activity> list = activityService.selectActivityList(activity);
        return getDataTable(list);
    }

    /**
     * 导出活动列表
     */
    @ApiOperation("导出活动列表")
    @PreAuthorize("@ss.hasPermi('index:activity:export')")
    @Log(title = "活动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Activity activity)
    {
        List<Activity> list = activityService.selectActivityList(activity);
        ExcelUtil<Activity> util = new ExcelUtil<Activity>(Activity.class);
        util.exportExcel(response, list, "活动数据");
    }

    /**
     * 获取活动详细信息
     */
    @ApiOperation("获取活动详细信息")
    @Anonymous
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(activityService.selectActivityById(id));
    }

    /**
     * 新增活动
     */
    @ApiOperation("新增活动")
    @PreAuthorize("@ss.hasPermi('index:activity:add')")
    @Log(title = "活动", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Activity activity)
    {
        return toAjax(activityService.insertActivity(activity));
    }

    /**
     * 修改活动
     */
    @ApiOperation("修改活动")
    @PreAuthorize("@ss.hasPermi('index:activity:edit')")
    @Log(title = "活动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Activity activity)
    {
        return toAjax(activityService.updateActivity(activity));
    }

    /**
     * 删除活动
     */
    @ApiOperation("删除活动")
    @PreAuthorize("@ss.hasPermi('index:activity:remove')")
    @Log(title = "活动", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(activityService.deleteActivityByIds(ids));
    }


    /**
     * 活动上架/下架 0 2 ->1 ; 1 -> 2
     */
    @ApiOperation("活动上架/下架 0 2 ->1 ; 1 -> 2")
    @Log(title = "活动上架/下架", businessType = BusinessType.UPDATE)
    @GetMapping("/manage/{id}")
    public AjaxResult manage(@PathVariable("id") Long id) {
        return toAjax(activityService.manage(id));
    }
}
